package main

import (
	"fmt"
	"sort"
)

//map默认不排序 可以通过sort对keys值进行排序 再通过key取出值来达到排序的效果
var (
	barVal = map[string]int{"alpha": 34, "bravo": 56, "charlie": 23,
		"delta": 87, "echo": 56, "foxtrot": 12,
		"golf": 34, "hotel": 16, "indio": 87,
		"juliet": 65, "kili": 43, "lima": 98}
)

func main() {
	fmt.Println("unsorted")
	for k, v := range barVal {
		fmt.Println(k, ":", v)
	}
	keys := make([]string, len(barVal))
	i := 0
	for k := range barVal {
		keys[i] = k
		i++
	}
	sort.Strings(keys)
	fmt.Println("")
	fmt.Println("sorted:")
	for _, k := range keys {
		fmt.Println(k, ":", barVal[k])
	}
}
